package com.lm.tika.example;

import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.txt.TXTParser;
import org.apache.tika.sax.BodyContentHandler;

import java.io.FileInputStream;

public class CustomParser {
    public static void main(String[] args) {
        try {
            FileInputStream inputStream = new FileInputStream("example.txt");

            BodyContentHandler handler = new BodyContentHandler();
            Metadata metadata = new Metadata();

            TXTParser parser = new TXTParser();
            parser.parse(inputStream, handler, metadata);

            System.out.println("📄文本内容: " + handler.toString());
            System.out.println("📜元数据: " + metadata.get(Metadata.CONTENT_TYPE));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
